/**
\file Button.qml
\brief Generic Button to build command toolbars

This button uses a single image on top of a rectangle, that changes color
when the mouse is pressed. It is useful to manage the button in several ways,
i.e. multistate buttons, buttons to be pressed when an alarm light is active etc.
To manage - when needed - a four-state button there are four colour shaded images
under the button icon itself:

- Button-off image for normal conditions
- Button-on image when button is clicked
- Button-alert image when button will show an alert message
- Button-alarm image when button will show and alarm message

The main \b buttonImage is set by default with the buttonOn icon. When implementing instances of
the button in the code (e.g. toolbars) the source value should be initialized to the
real icon to be shown.

\todo Implement a timer for alert light blinking and states to manage alert and alarm conditions
for the button instances.

\author © 2011 Enrico Miglino / Tech Consulting (enrico.miglino@ovi.com)
\author "Black Cat Cutting Studio" is protected by the copyright law
\author Distributed under the LGPL 3.0 license.
\version 1.0 alpha
\date 2011

\par Black Cat Cutting Studio licensing notes

    "Black Cat Cutting Studio" is free software: you can redistribute it
    and/or modify it under the terms of the Lesser GNU General Public License
    as published by the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    "Black Cat Cutting Studio" is distributed in the hope that it
    will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    Lesser GNU General Public License for more details.

    You should have received a copy of the Lesser GNU General Public License
    along with "Black Cat Cutting Studio".
    If not, see <http://www.gnu.org/licenses/>.

*/
import QtQuick 1.0

Item {
    id: container   // Button container

    signal clicked  // Managed signal for button handler
    property bool keyUsing: false

    // Alias of the button image
    property alias icon: buttonImage.source

    // Definition of the button off light
    Image {
        id: buttonOff

        width: container.width; height: container.height
        source: "../images/btn_off.png"
    }

    // Definition of the button on light
    Image {
        id: buttonOn

        width: container.width; height: container.height
        anchors.left: buttonOff.left
        anchors.right: buttonOff.right
        source: "../images/btn_on.png"
        opacity: 0
    }

    // Definition of the button alers light
    Image {
        id: buttonAlert

        width: container.width; height: container.height
        anchors.left: buttonOff.left
        anchors.right: buttonOff.right
        source: "../images/btn_alert.png"
        opacity: 0
    }

    // Definition of the button alarm light
    Image {
        id: buttonAlarm

        width: container.width; height: container.height
        anchors.left: buttonOff.left
        anchors.right: buttonOff.right
        source: "../images/btn_alarm.png"
        opacity: 0
    }

    // Definition of the button icon
    BorderImage {
        id: buttonImage

        anchors.left: buttonOff.left
        anchors.right: buttonOff.right
        width: container.width; height: container.height
        source: "../images/btn_off.png"
    }

    // Definition of the clickable area for the button
    MouseArea {
        id: mouseRegion

        anchors.fill: buttonImage
        onClicked: { container.clicked(); }
    }

    // States managed for the button
    states: [
        State {
            name: "Pressed"
            when: mouseRegion.pressed == true
            PropertyChanges { target: buttonOn; opacity: 1; }
        }
    ]
}
